/*  
  -- The Lime II Project -- 

  A tuplespaces-based middleware for coordinating agents and mobile hosts.
  Copyright (C) 2005.
  Gian Pietro Picco, Amy L. Murphy, Lorenzo Bellini.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/

package lime2;

/**
 * The listener within a remote system reaction installed because of the installation of a "remote or unspecified case"
 * weak reaction.
 * 
 * @author Gian Pietro Picco
 * @author Amy Murphy
 * @author Lorenzo Bellini
 */

class SystemRemoteWeakR extends SystemListener
{
 // private data members	
 private byte type; 
 private String name;
 private LimeServerID target;
 private ReactionID id;
 private Reaction r;
 
 /**
  * Constructor method.
  * 
  * @param type REM_EVENTW / REM_RDW / REM_INW
  * @param name of the involved tuplespace 
  * @param target host to whom the event must be sent
  * @param id reaction identifier
  */
 SystemRemoteWeakR(byte type, String name, LimeServerID target, ReactionID id)
 {
  this.type = type;	
  this.name = name;	
  this.target = target;
  this.id = id;
  this.r = null;
 }
 
 /**
  * Sets the reaction to (re)register (.. must be invoked only in the case of REM_INW).
  * 
  * @param r reaction to (re)register 
  */
 void setReRegistration(Reaction r)
 {
  this.r = r;
 }
 
 /**
  * This method is invoked automatically by the Lime system when the corresponding reaction must fire. 
  * 
  * @param re ReactionEvent
  */ 
 public void reactsToOut(ReactionEvent re)
 { 	
  // .. please note we leave the door opened for notifying events to the whole tuplespace or to a "third" host: the
  // listener knows the "subscriber"
 	
  switch (type)
  {
   case LimeConstants.REM_EVENTW:
        CommunicationMgr.get().postEvent(new RemWeakOp(type, LimeConstants.OPEN, name, target, id, re, r));	 
        break;
   case LimeConstants.REM_RDW:
   	    CommunicationMgr.get().postEvent(new RemWeakOp(type, LimeConstants.OPEN, name, target, id, re, r));
        break; 
   case LimeConstants.REM_INW:   
   	    CommunicationMgr.get().postEvent(new RemWeakOp(type, LimeConstants.OPEN, name, target, id, re, r));
        break;	
  }
 } 
	
}
